<template>
<trading-vue :data="chart" :width="this.width" :height="this.height"
        ref="tvjs"
        title-txt="The King"
        :toolbar="true"
        :color-back="colors.colorBack"
        :color-grid="colors.colorGrid"
        :color-text="colors.colorText">
</trading-vue>
</template>

<script>
import TradingVue from '../../src/TradingVue.vue'
import Data from '../data/data_tools.json'
import Utils from '../../src/stuff/utils.js'
import DataCube from '../../src/helpers/datacube.js'

export default {
    name: 'Toolbar',
    icon: '🔪',
    description: 'Toolbar & drawing tools',
    props: ['night'],
    components: {
        TradingVue
    },
    methods: {
        onResize(event) {
            this.width = window.innerWidth
            this.height = window.innerHeight - 50
        }
    },
    mounted() {
        window.addEventListener('resize', this.onResize)
        this.onResize()
        window.DataCube = this.chart
        window.tv = this.$refs.tvjs
        setTimeout(() => this.$set(this, 'chart', new DataCube(Data)), 1000)
    },
    computed: {
        colors() {
            return this.$props.night ? {} : {
                colorBack: '#fff',
                colorGrid: '#eee',
                colorText: '#333'
            }
        },
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.onResize)
    },
    data() {
        return {
            chart: {},
            width: window.innerWidth,
            height: window.innerHeight
        }
    }
}
</script>

<style>

</style>
